function validate(email) {
  if (!email.includes('@')) return false;
  const [local, domain] = email.split('@');
  const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  const chars = "0123456789.-_" + letters;
  if (local[0] === '.' || local[local.length-1] === '.') return false;
  for (const localChar of local) {
    if (!chars.includes(localChar)) return false;
  }
  const dotIndex = domain.indexOf('.');
  if (domain[dotIndex+1] === '.') return false;
  if (dotIndex < 0) return false;
  const parts = domain.split('.');
  const root = parts[parts.length-1];
  if (root.length < 2) return false;
  for (const domainChar of root) {
    if (!letters.includes(domainChar)) return false;
  }
  return true;
}



let output = validate("a@b.cd");
console.log(output);